package com.uniview.config;

import com.uniview.properties.OpenCommonProperties;
import com.uniview.utils.SnowflakeIdGenerator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author lux
 * @date: 2020/1/6
 * @desc: 自动配置文件
 */
@Slf4j
@Configuration
public class AutoConfiguration {
    /**
     * ID生成器配置
     *
     * @param properties
     * @return
     */
    @Bean
    @ConditionalOnMissingBean(OpenCommonProperties.class)
    public SnowflakeIdGenerator snowflakeIdWorker(OpenCommonProperties properties) {
        SnowflakeIdGenerator snowflakeIdGenerator = new SnowflakeIdGenerator(properties.getWorkId(), properties.getCenterId());
        log.info("SnowflakeIdGenerator [{}]", snowflakeIdGenerator);
        return snowflakeIdGenerator;
    }

}
